#include "RCKeyboardStateManager.h"

RCKeyboardStateManager::RCKeyboardStateManager(void)
{ 
	Enabled = true;
}


RCKeyboardStateManager::~RCKeyboardStateManager(void)
{
	keyboardState[0] = 0; 
	//keyboard->Release();
}

LPDIRECTINPUTDEVICE8 RCKeyboardStateManager::InitializeDevice(HWND hwnd)
{
	LPDIRECTINPUT8 p_dx_KeybObject;
	
	DirectInput8Create(GetModuleHandle(NULL), DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&p_dx_KeybObject, NULL);
	p_dx_KeybObject->CreateDevice(GUID_SysKeyboard, &keyboard, NULL);

	keyboard->SetDataFormat(&c_dfDIKeyboard);
	keyboard->SetCooperativeLevel(hwnd, DISCL_BACKGROUND|DISCL_FOREGROUND|DISCL_NONEXCLUSIVE);
	keyboard->Acquire();

	return keyboard;
}

char* RCKeyboardStateManager::getState()
{
	return keyboardState;
}

void RCKeyboardStateManager::Update(float time)
{
	keyboardState[0] = 0;
	HRESULT res = keyboard->GetDeviceState(sizeof(keyboardState),(LPVOID)&keyboardState);		
}

LPDIRECTINPUTDEVICE8 RCKeyboardStateManager::getDevice()
{
	return keyboard;
}

bool RCKeyboardStateManager::getEnabled()
{
	return Enabled;
}
void RCKeyboardStateManager::setEnabled(bool value)
{
	Enabled = value;
}